<template>
    <div class="login">
        <div class="main">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="登录">
                </el-form-item>
                <el-form-item label="账号" prop="id">
                    <el-input v-model="ruleForm.id"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="ruleForm.password" @keyup.native.enter="submitForm('ruleForm')"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </el-form-item>
            </el-form>

        </div>
    </div>
</template>

<script>
    import {
        setToken
    } from "../untial/cook"
    import {
        checkoutlogin
    } from "../api/interface"
    export default {
        data() {
            return {
                ruleForm: {
                    id: '',
                    password: '',
                },
                rules: {
                    id: [{
                        required: true,
                        message: '请输入账号',
                        trigger: 'blur'
                    }, ],
                    password: [{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur'
                    }, ],
                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        checkoutlogin(this.ruleForm).then(res => {
                            if (res.code == 200) {
                                this.$message.success('登陆成功，即将进行跳转~~~');
                                setToken('token', res.data);
                                // console.log(getToken('token'));
                                this.$router.push("/");
                            } else {
                                this.$message.error('请注意！你的账号或密码错了哦！');
                            }
                        });
                    } else {
                        this.$message.warning('请注意完善表单信息！');
                        return false;
                    }
                });
            },
        }
    }
</script>

<style lang="less" scoped>
    .login {
        background: url("../images/beijing.png");
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;

        .main {
            display: flex;
            flex-direction: row;
            justify-content: flex-end;
            width: 50%;
            height: 60%;
            box-sizing: border-box;
            background-image: url("../images/denglu_03.png");
            background-size: 100% 100%;
            padding-right: 4%;

            form {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
            }
        }
    }
</style>